<?php
class Plugin {
  public $name = 'Enquery Form';
  
  public $folder = 'enq';
  
  public function data($instance_id) {
    $data = new stdClass();
    $data->folder = $this->folder;
    $data->instance_id = $instance_id;
    
    require_once dirname(__FILE__) . '/../../common.inc.php';
    $cond_vals = new stdClass();
    $cond_vals->c = 't.instance_id = :v1';
    $cond_vals->v = array(':v1' => $instance_id);
    $result = DbUtils::get(DbUtils::createPdoInst(), TABLE_NAME_PREFIX_PLUGIN . $this->folder . '_email', $cond_vals, NULL, NULL, NULL, NULL, NULL);
    
    $email = new stdClass();
    $email->mail_to = '';
    
    if (count($result->d) > 0) {
      $email = $result->d[0];
    }
    if (!isset($email->id)) {
      $email->track_id = MiscUtils::unique();
      $email->instance_id = $instance_id;
    }
    $data->email = $email;
    
    $cond_vals = new stdClass();
    $cond_vals->c = 't.instance_id = :v1';
    $cond_vals->v = array(':v1' => $instance_id);
    $result = DbUtils::get(DbUtils::createPdoInst(), TABLE_NAME_PREFIX_PLUGIN . $this->folder . '_config', $cond_vals, NULL, NULL, NULL, NULL, NULL);
    
    $data->configs = $result->d;
    
    return $data;
  }
  
  public function back($data) {
    $instance_id = $data->instance_id;
     require_once dirname(__FILE__) . '/back.php';
  }
  
  public function front($data) {  
    require_once dirname(__FILE__) . '/../../common.inc.php';
    require_once dirname(__FILE__) . '/front.php';
  }
}
?>